package com.myh.cc.coom.recommend.viewmodel

import android.view.View
import com.bumptech.glide.Glide
import com.myh.cc.base.BaseModel
import com.myh.cc.coom.recommend.adapter.RecommendDetailsAdapter
import com.myh.cc.coom.recommend.bean.RecommendDetaislBean
import com.myh.cc.coom.recommend.net.RecommendNetControl
import com.myh.cc.databinding.ActivityRecommendDetailsBinding
import com.myh.cc.util.ConstantUtil
import com.myh.cc.widget.OnItemClickListener

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/18.   ：
 */
class RecommendDetailsModel: BaseModel<ActivityRecommendDetailsBinding,RecommendNetControl>(),OnItemClickListener {

    //lateinit var albummid：String

    override fun onBeforeRequest(tag: Int) {
    }

    override fun onSuccess(data: Any, tag: Int) {
        initRecycleView(data as RecommendDetaislBean)
    }

    override fun onError(errorMag: String, tag: Int) {
    }

    // 专辑id
    fun getRecommendDetails(albummid: String){

        var map = HashMap<String,String>()
        map.put("albummid",albummid)
        map.put("format","json")
        mControl.getRecommendDetails(this,"",map,ConstantUtil.requestTagOne)
    }

    fun initRecycleView(bean: RecommendDetaislBean){

        val  adapter = RecommendDetailsAdapter(bean)
        val picUrl = "http://y.gtimg.cn/music/photo_new/T002R300x300M000"+bean.data.mid+".jpg?max_age=2592000"


        mBinder.rdTvDesc.text = "专辑 共"+bean.data.total+"首"
        mBinder.rdTvName.text = bean.data.name
        mBinder.tvInfo.text = bean.data.desc
        Glide.with(getContext()).load(picUrl).into(mBinder.rdIvImg)

        mBinder.rdDetialsRv.adapter = adapter

        adapter.mListener = this

    }

    override fun onClick(view: View, position: Int) {
    }

    override fun onItemLongClick(view: View, position: Int) {
    }
}